import { createRouter, createWebHistory } from 'vue-router'
import routes from './routes'
import {useCookies} from "@vueuse/integrations/useCookies";


const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to,from,next)=>{
  const token = useCookies().get("user-token")
  //
  if (to.path === '/search' || to.path === '/' ||to.path === '/video' ||to.path === '/login'){
    return next()
  }
  //判断是否登录
  if (!token && to.path !== "/adminI-AM-WASTE/login"){
    return next({path:'/adminI-AM-WASTE/login'})
  }
  //判断是否重复登录
  if (token && to.path === '/adminI-AM-WASTE/login'){
    return next({path: from.path ? from.path : '/adminI-AM-WASTE/videoList'})
  }

  next()
})

export default router
